Passed
Push — master ( d7cb50...defd53 )
by EMP
01:16
created

main.js ➔ displayMsg   F

Complexity

Conditions 23

Size

Total Lines 70
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 70
rs 0
c 0
b 0
f 0
cc 23

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like main.js ➔ displayMsg often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
"use strict";
2
3
sodium.ready.then(function() {
1 ignored issue
show
Bug introduced by
The variable sodium seems to be never declared. If this is a global, consider adding a /** global: sodium */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
4
5
const ae = new AllEars(function(ok) {
1 ignored issue
show
Bug introduced by
The variable AllEars seems to be never declared. If this is a global, consider adding a /** global: AllEars */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
6
	if (ok) {
7
		document.getElementById("txt_skey").style.background = "#404b41";
8
		document.getElementById("txt_skey").maxLength = "64";
9
	} else {
10
		console.log("Failed to load All-Ears");
11
	}
12
});
13
14
let tab="inbox";
15
let page=0;
0 ignored issues
show
Unused Code introduced by
The variable page seems to be never used. Consider removing it.
Loading history...
16
17
// Helper functions
18
function getCountryName(countryCode) {
19
	const opts = document.getElementById("gatekeeper_country");
20
21
	for (let i = 0; i < opts.length; i++) {
22
		if (opts[i].value === countryCode) {
23
			return opts[i].textContent;
24
		}
25
	}
26
27
	return "Unknown countrycode: " + countryCode;
28
}
29
30
function getCountryFlag(countryCode) {
31
	const regionalIndicator1 = 127462 + countryCode.codePointAt(0) - 65;
32
	const regionalIndicator2 = 127462 + countryCode.codePointAt(1) - 65;
33
	return "&#" + regionalIndicator1 + ";&#" + regionalIndicator2 + ";";
34
}
35
36
function displayMsg(isInt, num) {
37
	document.getElementById("midright").scroll(0, 0);
38
39
	const ts = isInt? ae.GetIntMsgTime(num) : ae.GetExtMsgTime(num);
40
41
	document.getElementById("btn_reply").disabled = false;
42
	document.getElementById("btn_reply").onclick = function() {
43
		document.getElementById("write_recv").value = isInt ? ae.GetIntMsgFrom(num) : ae.GetExtMsgFrom(num);
44
		document.getElementById("write_subj").value = "Re: " + (isInt ? ae.GetIntMsgTitle(num) : ae.GetExtMsgTitle(num));
45
		document.getElementById("btn_write").click();
46
		document.getElementById("div_write_1").hidden = false;
47
		document.getElementById("div_write_2").hidden = true;
48
		document.getElementById("write_body").focus();
49
		for (const opt of document.getElementById("write_from").options) {
50
			if (opt.value === (isInt ? ae.GetIntMsgTo(num) : ae.GetExtMsgTo(num))) {
51
				opt.selected = true;
52
			}
53
		}
54
	};
55
56
	document.getElementById("msg").hidden = false;
57
	document.getElementById("msg").getElementsByTagName("h1")[0].textContent = isInt ? ae.GetIntMsgTitle(num) : ae.GetExtMsgTitle(num);
58
	document.getElementById("msg").getElementsByTagName("pre")[0].textContent = isInt ? ae.GetIntMsgBody(num) : ae.GetExtMsgBody(num);
59
60
	document.getElementById("readmsg_to").textContent = isInt ? ae.GetIntMsgTo(num) : ae.GetExtMsgTo(num);
61
	document.getElementById("readmsg_date").children[0].textContent = new Date(ts * 1000).toISOString().slice(0, 19).replace("T", " ");
62
63
	if (!isInt) {
64
		document.getElementById("readmsg_ip").hidden = false;
65
		document.getElementById("readmsg_flags").hidden = false;
66
		document.getElementById("readmsg_country").hidden = false;
67
		document.getElementById("readmsg_tls").hidden = false;
68
		document.getElementById("readmsg_greet").hidden = false;
69
		document.getElementById("readmsg_timing").hidden = false;
70
		document.getElementById("readmsg_envfrom").hidden = false;
71
72
		const cc = ae.GetExtMsgCountry(num);
73
74
		document.getElementById("readmsg_ip").children[0].textContent = ae.GetExtMsgIp(num);
75
		document.getElementById("readmsg_country").innerHTML = getCountryFlag(cc) + " " + getCountryName(cc);
76
		document.getElementById("readmsg_tls").children[0].textContent = ae.GetExtMsgTLS(num);
77
		document.getElementById("readmsg_greet").children[0].textContent = ae.GetExtMsgGreet(num);
78
		document.getElementById("readmsg_envfrom").textContent = ae.GetExtMsgFrom(num);
79
80
		let flagText = "";
81
		if (!ae.GetExtMsgFlagPExt(num)) flagText += "<abbr title=\"The sender did not use the Extended (ESMTP) protocol\">SMTP</abbr> ";
82
		if (!ae.GetExtMsgFlagQuit(num)) flagText += "<abbr title=\"The sender did not issue the required QUIT command\">QUIT</abbr> ";
83
		if (ae.GetExtMsgFlagRare(num)) flagText += "<abbr title=\"The sender issued unusual command(s)\">RARE</abbr> ";
84
		if (ae.GetExtMsgFlagFail(num)) flagText += "<abbr title=\"The sender issued invalid command(s)\">FAIL</abbr> ";
85
		if (ae.GetExtMsgFlagPErr(num)) flagText += "<abbr title=\"The sender violated the protocol\">PROT</abbr> ";
86
		document.getElementById("readmsg_flags").children[0].innerHTML = flagText.trim();
87
	} else {
88
		document.getElementById("readmsg_ip").hidden = true;
89
		document.getElementById("readmsg_flags").hidden = true;
90
		document.getElementById("readmsg_country").hidden = true;
91
		document.getElementById("readmsg_tls").hidden = true;
92
		document.getElementById("readmsg_greet").hidden = true;
93
		document.getElementById("readmsg_timing").hidden = true;
94
		document.getElementById("readmsg_envfrom").hidden = true;
95
96
		let symbol = "<span title=\"Invalid level\">&#x26a0;</span>";
97
		if (ae.GetIntMsgFrom(num) === "system") {if (ae.GetIntMsgLevel(num) === 3) symbol = "<span title=\"System\">&#x1f162;</span>";} // S (System)
98
		else if (ae.GetIntMsgLevel(num) === 0) symbol = "<span title=\"Level 0 User\">&#x1f10c;</span>"; // 0
99
		else if (ae.GetIntMsgLevel(num) === 1) symbol = "<span title=\"Level 1 User\">&#x278a;</span>"; // 1
100
		else if (ae.GetIntMsgLevel(num) === 2) symbol = "<span title=\"Level 2 User\">&#x278b;</span>"; // 2
101
		else if (ae.GetIntMsgLevel(num) === 3) symbol = "<span title=\"Administrator\">&#x1f150;</span>"; // A (Admin)
102
103
		document.getElementById("readmsg_from").innerHTML = symbol + " " + ae.GetIntMsgFrom(num);
104
	}
105
}
106
107
// Interface
108
function addMsg(isInt, i) {
109
	const inbox = document.getElementById("tbl_inbox");
110
	const sent = document.getElementById("tbl_sent");
111
112
	const isSent = false; //TODO
113
	const table = isSent ? sent : inbox;
114
115
	const row = table.insertRow(-1);
116
	const cellTime = row.insertCell(-1);
117
	const cellSubj = row.insertCell(-1);
118
	const cellSnd1 = row.insertCell(-1);
119
	const cellSnd2 = row.insertCell(-1);
120
121
	const ts = isInt? ae.GetIntMsgTime(i) : ae.GetExtMsgTime(i);
122
	cellTime.setAttribute("data-ts", ts);
123
	cellTime.textContent = new Date(ts * 1000).toISOString().slice(0, 10);
124
125
	cellSubj.textContent = isInt? ae.GetIntMsgTitle(i) : ae.GetExtMsgTitle(i);
126
127
	if (isInt) {
128
		cellSnd1.textContent = ae.GetIntMsgFrom(i);
129
		cellSnd1.className = (ae.GetIntMsgFrom(i).length === 16) ? "mono" : "";
130
	} else {
131
		const from1 = ae.GetExtMsgFrom(i);
132
		const from2 = from1.substring(from1.indexOf("@") + 1);
133
		const cc = ae.GetExtMsgCountry(i);
134
135
		cellSnd1.textContent = from1.substring(0, from1.indexOf("@"));
136
		cellSnd2.innerHTML = "<abbr title=\"" + getCountryName(cc) + "\">" + getCountryFlag(cc) + "</abbr>";
137
138
		const fromText = document.createElement("span");
139
		fromText.textContent = " " + from2;
140
		cellSnd2.appendChild(fromText);
141
	}
142
143
//	divDel.innerHTML = "<input class=\"delMsg\" type=\"checkbox\" data-id=\"" + ae.GetIntMsgIdHex(i) + "\">";
144
145
	row.onclick = function() {
146
		displayMsg(isInt, i);
147
	};
148
/*
149
	cellDel.children[0].onchange = function() {
150
		if (!divDel.children[0].checked) {
151
			const checkboxes = elmt.getElementsByTagName("input");
152
			let checked = false;
153
154
			for (let j = 0; j < checkboxes.length; j++) {
155
				if (checkboxes[j].checked) {
156
					checked = true;
157
					break;
158
				}
159
			}
160
161
			if (!checked) {
162
				document.getElementById(isSent ? "btn_sentdel" : "btn_msgdel").hidden = true;
163
				return;
164
			}
165
		}
166
167
		document.getElementById(isSent? "btn_sentdel" : "btn_msgdel").hidden = false;
168
	};
169
*/
170
}
171
172
function addMessages() {
173
	const maxExt = ae.GetExtMsgCount();
174
	const maxInt = ae.GetIntMsgCount();
175
176
	let numExt = 0;
177
	let numInt = 0;
178
179
	while(1) {
180
		const tsInt = (numInt < maxInt) ? ae.GetIntMsgTime(numInt) : 0;
181
		const tsExt = (numExt < maxExt) ? ae.GetExtMsgTime(numExt) : 0;
182
		if (tsInt === 0 && tsExt === 0) break;
183
184
		if (tsInt !== 0 && (tsExt === 0 || tsInt > tsExt)) {
185
			addMsg(true, numInt);
186
			numInt++;
187
		} else if (tsExt !== 0) {
188
			addMsg(false, numExt);
189
			numExt++;
190
		}
191
	}
192
}
193
194
function clearMessages() {
195
	document.getElementById("tbl_inbox").innerHTML = "";
196
//	document.getElementById("tbl_sentm").innerHTML = "";
197
//	document.getElementById("tbl_notes").innerHTML = "";
198
//	document.getElementById("tbl_files").innerHTML = "";
199
}
200
201
function updateAddressCounts() {
202
	document.getElementById("limit_normal").textContent = (ae.GetAddressCountNormal() + "/" + ae.GetAddressLimitNormal(ae.GetUserLevel())).padStart(ae.GetAddressLimitNormal(ae.GetUserLevel()) > 9 ? 5 : 1);
203
	document.getElementById("limit_shield").textContent = (ae.GetAddressCountShield() + "/" + ae.GetAddressLimitShield(ae.GetUserLevel())).padStart(ae.GetAddressLimitShield(ae.GetUserLevel()) > 9 ? 5 : 1);
204
	document.getElementById("limit_total").textContent = ((ae.GetAddressCountNormal() + ae.GetAddressCountShield()) + "/" + ae.GetAddrPerUser()).padStart(5);
205
}
206
207
function reloadInterface() {
208
	document.getElementById("div_begin").hidden = true;
209
	document.getElementById("div_main").style.display = "grid";
210
211
	// Contacts
212
	for (let i = 0; i < ae.GetContactCount(); i++) {
213
		addContact(
214
			ae.GetContactMail(i),
215
			ae.GetContactName(i),
216
			ae.GetContactNote(i)
217
		);
218
	}
219
220
	// Addresses
221
	for (let i = 0; i < ae.GetAddressCount(); i++) {
222
		addAddress(i);
223
	}
224
225
	document.getElementById("table_addrs").getElementsByTagName("caption")[0].textContent = "Level " + ae.GetUserLevel() + " User";
226
	updateAddressCounts();
227
}
228
229 View Code Duplication
function deleteAddress(addr) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
230
	let btns = document.getElementById("tbl_addrs").getElementsByTagName("button");
231
	for (let i = 0; i < btns.length; i++) btns[i].disabled = true;
232
233
	let addressToDelete = -1;
234
235
	for (let i = 0; i < ae.GetAddressCount(); i++) {
236
		if (addr === ae.GetAddress(i)) {
237
			addressToDelete = i;
238
			break;
239
		}
240
	}
241
242
	if (addressToDelete === -1) return;
243
244
	ae.Address_Delete(addressToDelete, function(success) {
245
		if (success) {
246
			document.getElementById("tbl_addrs").deleteRow(addressToDelete);
247
			document.getElementById("write_from").remove(addressToDelete);
248
			updateAddressCounts();
249
250
			if (ae.GetAddressCountNormal() < ae.GetAddressLimitNormal(ae.GetUserLevel())) document.getElementById("btn_address_create_normal").disabled = false;
251
			if (ae.GetAddressCountShield() < ae.GetAddressLimitShield(ae.GetUserLevel())) document.getElementById("btn_address_create_shield").disabled = false;
252
253
			ae.Private_Update(function(success2) {
254
				if (!success2) console.log("Failed to update the Private field");
255
256
				btns = document.getElementById("tbl_addrs").getElementsByTagName("button");
257
				for (let i = 0; i < btns.length; i++) btns[i].disabled = false;
258
			});
259
		} else {
260
			console.log("Failed to delete address");
261
262
			btns = document.getElementById("tbl_addrs").getElementsByTagName("button");
263
			for (let i = 0; i < btns.length; i++) btns[i].disabled = false;
264
		}
265
	});
266
}
267
268 View Code Duplication
function shieldMix(addr) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
269
	let newAddr = "";
270
271
	for (let i = 0; i < 16; i++) {
272
		switch (addr.charAt(i)) {
273
			case '1':
274
				newAddr += "1iIlL".charAt(Math.floor(Math.random() * 5));
275
				break;
276
			case '0':
277
				newAddr += "0oO".charAt(Math.floor(Math.random() * 3));
278
				break;
279
			case 'w':
280
				newAddr += "VvWw".charAt(Math.floor(Math.random() * 4));
281
				break;
282
			default:
283
				newAddr += (Math.random() > 0.5) ? addr.charAt(i) : addr.charAt(i).toUpperCase();
284
		}
285
	}
286
287
	return newAddr;
288
}
289
290
function addAddress(num) {
291
	const addrTable = document.getElementById("tbl_addrs");
292
	const row = addrTable.insertRow(-1);
293
	const cellAddr = row.insertCell(-1);
294
	const cellChk1 = row.insertCell(-1);
295
	const cellChk2 = row.insertCell(-1);
296
	const cellChk3 = row.insertCell(-1);
297
	const cellBtnD = row.insertCell(-1);
298
299
	cellAddr.textContent = ae.GetAddress(num);
300
	cellAddr.onclick = function() {
301
		if (cellAddr.textContent.length === 16)
302
			navigator.clipboard.writeText(shieldMix(cellAddr.textContent) + "@" + ae.GetDomain());
1 ignored issue
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
303
		else
304
			navigator.clipboard.writeText(cellAddr.textContent + "@" + ae.GetDomain());
305
	};
306
307
	cellChk1.innerHTML = ae.GetAddressAccExt(num) ? "<input type=\"checkbox\" checked=\"checked\">" : "<input type=\"checkbox\">";
308
	cellChk2.innerHTML = ae.GetAddressAccInt(num) ? "<input type=\"checkbox\" checked=\"checked\">" : "<input type=\"checkbox\">";
309
	cellChk3.innerHTML = ae.GetAddressUse_Gk(num) ? "<input type=\"checkbox\" checked=\"checked\">" : "<input type=\"checkbox\">";
310
311
	cellBtnD.innerHTML = "<button type=\"button\">X</button>";
312
	cellBtnD.onclick = function() {deleteAddress(cellAddr.textContent);};
313
314
	const opt = document.createElement("option");
315
	opt.value = cellAddr.textContent;
316
	opt.textContent = cellAddr.textContent + "@" + ae.GetDomain();
317
	document.getElementById("write_from").appendChild(opt);
318
}
319
320
document.getElementById("btn_updt").onclick = function() {
321
	const btn = this;
322
	btn.disabled = true;
323
	btn.blur();
324
325
	if (tab === "inbox") {
326
		document.getElementById("tbl_inbox").style.opacity = 0.5;
327
328
		ae.Message_Browse(true, function(successBrowse) {
329
			document.getElementById("tbl_inbox").style.opacity = 1;
330
331
			if (successBrowse) {
332
				clearMessages();
333
				addMessages();
334
				btn.disabled = false;
335
			} else {
336
				console.log("Failed to refresh");
337
				btn.disabled = false;
338
			}
339
		});
340
	}
341
};
342
343
function addContact(mail, name, note) {
344
	const tbl = document.getElementById("tbl_ctact");
345
	const row = tbl.insertRow(-1);
346
	const cellMail = row.insertCell(-1);
347
	const cellName = row.insertCell(-1);
348
	const cellNote = row.insertCell(-1);
349
	const cellBtnD = row.insertCell(-1);
350
351
	cellMail.textContent = mail;
352
	cellName.textContent = name;
353
	cellNote.textContent = note;
354
	cellBtnD.innerHTML = "<button type=\"button\">X</button>";
355
356
	cellMail.contentEditable = true;
357
	cellName.contentEditable = true;
358
	cellNote.contentEditable = true;
359
360
	cellBtnD.onclick = function() {row.remove();};
361
}
362
363
document.getElementById("btn_newcontact").onclick = function() {
364
	addContact("", "", "");
365
}
366
367
// Tabs
368
function setupButtons() {
369
	switch(tab) {
370
		case "inbox":
371
		case "snbox":
372
			document.getElementById("btn_dele").disabled = false;
373
			document.getElementById("btn_left").disabled = false; // depends
374
			document.getElementById("btn_cent").disabled = true;
375
			document.getElementById("btn_rght").disabled = false;
376
			document.getElementById("btn_updt").disabled = false;
377
		break;
378
		case "write":
379
			document.getElementById("btn_dele").disabled = false; // depends
380
			document.getElementById("btn_left").disabled = false; // depends
381
			document.getElementById("btn_cent").disabled = true;
382
			document.getElementById("btn_rght").disabled = false;
383
			document.getElementById("btn_updt").disabled = true;
384
		break;
385
		case "notes":
386
			document.getElementById("btn_dele").disabled = true;
387
			document.getElementById("btn_left").disabled = false; // depends
388
			document.getElementById("btn_cent").disabled = true;
389
			document.getElementById("btn_rght").disabled = false; // depends
390
			document.getElementById("btn_updt").disabled = true; // depends
391
		break;
392
		case "prefs":
393
			document.getElementById("btn_dele").disabled = true;
394
			document.getElementById("btn_left").disabled = false; // depends
395
			document.getElementById("btn_cent").disabled = true;
396
			document.getElementById("btn_rght").disabled = false; // depends
397
			document.getElementById("btn_updt").disabled = true; // depends
398
		break;
399
	}
400
}
401
402
document.getElementById("btn_left").onclick = function() {
403
	switch (tab) {
404
		case "write":
405
			document.getElementById("div_write_1").hidden = false;
406
			document.getElementById("div_write_2").hidden = true;
407
			document.getElementById("write_body").focus();
408
		break;
409
	}
410
411
	this.blur();
412
};
413
414
document.getElementById("btn_rght").onclick = function() {
415
	switch (tab) {
416
		case "write":
417
			if (!document.getElementById("div_write_1").hidden) {
418
				ae.Address_Lookup(document.getElementById("write_recv").value, function(pk) {
419
					if (pk) {
420
						document.getElementById("div_write_1").hidden = true;
421
						document.getElementById("div_write_2").hidden = false;
422
423
						document.getElementById("write2_from").textContent = document.getElementById("write_from").value + "@" + ae.GetDomain();
424
						document.getElementById("write2_recv").textContent = document.getElementById("write_recv").value;
425
						document.getElementById("write2_pkey").textContent = sodium.to_hex(pk);
1 ignored issue
show
Bug introduced by
The variable sodium seems to be never declared. If this is a global, consider adding a /** global: sodium */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
426
427
						document.getElementById("write2_subj").textContent = document.getElementById("write_subj").value;
428
						document.getElementById("write2_body").textContent = document.getElementById("write_body").value;
429
					} else {
430
						console.log("Failed lookup");
431
					}
432
				});
433
			} else if (!document.getElementById("div_write_2").hidden) {
434
				ae.Message_Create(document.getElementById("write_subj").value, document.getElementById("write_body").value, document.getElementById("write_from").value, document.getElementById("write_recv").value, sodium.from_hex(document.getElementById("write2_pkey").textContent), function(success) {
1 ignored issue
show
Bug introduced by
The variable sodium seems to be never declared. If this is a global, consider adding a /** global: sodium */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
435
					if (success) {
436
						console.log("Sent ok");
437
					} else {
438
						console.log("Failed sending");
439
					}
440
				});
441
			}
442
		break;
443
	}
444
445
	this.blur();
446
};
447
448
for (const btn1 of document.getElementById("main1").getElementsByClassName("top")[0].getElementsByTagName("button")) {
449
	btn1.onclick = function() {
450
		for (const btn2 of document.getElementById("main1").getElementsByClassName("top")[0].getElementsByTagName("button")) {
451
			const isMatch = (btn1 === btn2);
452
			btn2.disabled = isMatch;
453
			document.getElementById("div_" + btn2.id.slice(4)).hidden = !isMatch;
454
455
			if (isMatch) {
456
				tab = btn2.id.slice(4);
457
				setupButtons();
458
			}
459
		}
460
	};
461
};
462
463
function addressCreate(addr) {
464
	const btnN = document.getElementById("btn_address_create_normal");
465
	const btnS = document.getElementById("btn_address_create_shield");
466
	btnN.disabled = true;
467
	btnS.disabled = true;
468
469
	ae.Address_Create(addr, function(success1) {
470
		if (success1) {
471
			ae.Private_Update(function(success2) {
472
				addAddress(ae.GetAddressCount() - 1);
473
				if (addr !== "SHIELD") document.getElementById("txt_address_create_normal").value = "";
474
				updateAddressCounts();
475
476
				if (!success2) console.log("Failed to update the Private field");
477
478
				if (ae.GetAddressCountNormal() < ae.GetAddressLimitNormal(ae.GetUserLevel())) btnN.disabled = false;
479
				if (ae.GetAddressCountShield() < ae.GetAddressLimitShield(ae.GetUserLevel())) btnS.disabled = false;
480
			});
481
		} else {
482
			console.log("Failed to add address");
483
484
			if (ae.GetAddressCountNormal() < ae.GetAddressLimitNormal(ae.GetUserLevel())) btnN.disabled = false;
485
			if (ae.GetAddressCountShield() < ae.GetAddressLimitShield(ae.GetUserLevel())) btnS.disabled = false;
486
		}
487
	});
488
}
489
490
document.getElementById("btn_address_create_normal").onclick = function() {
491
	if (ae.GetAddressCountNormal() >= ae.GetAddressLimitNormal(ae.GetUserLevel())) return;
492
493
	const txtNewAddr = document.getElementById("txt_address_create_normal");
494
	if (!txtNewAddr.reportValidity()) return;
495
496
	addressCreate(txtNewAddr.value);
497
}
498
499
document.getElementById("btn_address_create_shield").onclick = function() {
500
	if (ae.GetAddressCountShield() >= ae.GetAddressLimitShield(ae.GetUserLevel())) return;
501
502
	addressCreate("SHIELD");
503
};
504
505
document.getElementById("txt_skey").onkeyup = function(event) {
506
	if (event.key === "Enter") {
507
		event.preventDefault();
508
		document.getElementById("btn_enter").click();
509
	}
510
};
511
512
document.getElementById("btn_enter").onclick = function() {
513
	const txtSkey = document.getElementById("txt_skey");
514
	if (!txtSkey.reportValidity()) return;
515
516
	const btn = this;
517
	btn.disabled = true;
518
	document.getElementById("txt_skey").style.background = "#111";
519
520
	ae.SetKeys(txtSkey.value, function(successSetKeys) {
521
		if (successSetKeys) {
522
			ae.Account_Browse(0, function(successBrowse) {
523
				if (successBrowse) {
524
					txtSkey.value = "";
525
					reloadInterface();
526
					document.getElementById("btn_updt").click();
527
				} else {
528
					console.log("Failed to enter");
529
					btn.disabled = false;
530
					document.getElementById("txt_skey").style.background = "#404b41";
531
					txtSkey.focus();
532
				}
533
			});
534
		} else {
535
			console.log("Invalid format for key");
536
			btn.disabled = false;
537
			document.getElementById("txt_skey").style.background = "#404b41";
538
			txtSkey.focus();
539
		}
540
	});
541
};
542
543
});
544